package com.arcadia.d2dmg;

import com.arcadia.d2.hero.Hero;
import com.arcadia.d2.item_attributes.Item;

public class Calculator {

	private int attackDamage;
	private double magicalDamage;
	private double physicalDamage;
	private double pureDamage;
	private double compositeDamage;
	private double hpRemoval;
	private double universalDamage;
	
	public Calculator(Hero attacker, int lvOfAttacker, Item[] itemSlotOfAttacker, Hero defender, int lvOfDefender, Item[] itemSlotOfDefender, Double duration) {
		attacker.setLevel(lvOfAttacker);
		attacker.setItem(itemSlotOfAttacker);
		attacker.equip(itemSlotOfAttacker);
		
		defender.setLevel(lvOfDefender);
		defender.setItem(itemSlotOfDefender);
		defender.equip(itemSlotOfDefender);
		defender.getArmor().setIArmor(0, defender.getAttribute().getAgilityGrowth() * lvOfDefender);

		for (int i = 0; i < attacker.getAttackSpeed().timesOfAttack(duration); i++){
			this.attackDamage += attacker.getAttack().getAttackDamage(attacker.getAttribute().getIStrength(lvOfAttacker));
		}
		this.attackDamage = (int)(this.attackDamage * defender.getArmor().getPhysicsReduction()); 
	    for (int i = 0; i < attacker.getAbilities().size(); i++){
	    	this.magicalDamage += attacker.getAbilities().get(i).getMagicalDamage();
	    	this.physicalDamage += attacker.getAbilities().get(i).getPhysicalDamage();
	    	this.pureDamage += attacker.getAbilities().get(i).getPureDamage();
	    	this.compositeDamage += attacker.getAbilities().get(i).getCompositeDamage();
	    	this.hpRemoval += attacker.getAbilities().get(i).getHpRemoval();
	    	this.universalDamage += attacker.getAbilities().get(i).getUniversalDamage();
	    }
	    this.magicalDamage = (int)(this.magicalDamage * defender.getMagicRes().getMagicResistance(defender.getMagicRes().getBase(), defender.getMagicRes().getIMagicResistance()));

	}
	
	
	
	public int getAttackDamage() {
		return attackDamage;
	}

	public double getMagicalDamage() {
		return magicalDamage;
	}

	public double getPhysicalDamage() {
		return physicalDamage;
	}

	public double getPureDamage() {
		return pureDamage;
	}

	public double getCompositeDamage() {
		return compositeDamage;
	}

	public double getHpRemoval() {
		return hpRemoval;
	}

	public double getUniversalDamage() {
		return universalDamage;
	}

	public String toString(){
		double totalDamage = this.attackDamage + this.magicalDamage + this.physicalDamage + 
							 this.pureDamage + this.compositeDamage + this.hpRemoval + this.universalDamage;
		return String.valueOf(totalDamage);
	}
}
